package collect

import (
	"fmt"
	"github.com/StackExchange/wmi"
)

type service struct {
	Caption   string //描述信息
	Name      string //服务名称
	PathName  string //服务程序路径
	Started   bool   //是否已启动
	StartMode string //启动模式
	StartName string //启动用户
}

//获取windows操作系统服务列表
func GetServiceInfo() (resultdata []map[string]string) {
	var dst []service
	//err := wmi.Query("SELECT * FROM Win32_Service", &dst);
	//if err != nil {
	//	return resultdata
	//}

	wmi.Query("SELECT * FROM Win32_Service", &dst);
	for _, v := range dst {
		m := make(map[string]string)
		m["name"] = v.Name
		m["pathname"] = v.PathName
		if v.Started {
			m["started"] = "True"
		} else {
			m["started"] = "False"
		}
		m["startmode"] = v.StartMode
		m["startusername"] = v.StartName
		m["caption"] = v.Caption
		resultdata = append(resultdata, m)

		fmt.Println(m)
	}
	return resultdata
}

//////////////////////////////////////////////////////////////////////////////////
//获取Linux服务列表
func GetServiceInfoL() []map[string]string{
	var resultdata []map[string]string
	return resultdata
}